package com.mcptt.config.user.profile.sub.sub;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;
import com.mcptt.config.user.profile.UserProfile;
import com.mcptt.config.user.profile.sub.sub.sub.Entry;
import com.mcptt.db.model.UserInfo;

public class McGroupInfo
{
	public static final String Name_Mcptt = "MCPTTGroupInfo";
	public static final String Name_Mcvideo = "MCVideoGroupInfo";
	public static final String Name_Mcdata = "mcdataGroupInfo";

	private List<Entry> entryList = null;
	private int mcType = UserInfo.McType_Ptt;

	public void parse(int mcType,Element elem) throws JDOMException
	{
		if (elem == null)
		{
			return;
		}
		entryList = new Vector<Entry>();
		List<Element> list = elem.getChildren();// ��ø��ڵ���ӽڵ�
		for (Element subElem : list)
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			if (name == null || name.length() <= 0)
			{
				return;
			}
			if (name.equals(Entry.Name))
			{
				Entry entry = new Entry();
				entry.parse(subElem);
				entryList.add(entry);
			}
		}
	}

	public List<Entry> getEntryList()
	{
		return entryList;
	}

	public String toString()
	{
		String name = getNameByMcType(mcType);
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(name).append(">").append("\r\n");

		for (Iterator<Entry> itor = entryList.iterator(); itor.hasNext();)
		{
			strBuf.append(itor.next()).append("\r\n");
		}

		strBuf.append("</").append(name).append(">").append("\r\n");

		return strBuf.toString();
	}
	
	private String getNameByMcType(int type)
	{
		if(type == UserInfo.McType_Ptt)
    	{
    		return Name_Mcptt;
    	}
    	else if(type == UserInfo.McType_Video)
    	{
    		return Name_Mcvideo;
    	}
    	else if(type == UserInfo.McType_Data)
    	{
    		return Name_Mcdata;
    	}
		return Name_Mcptt;
	}
}
